﻿//_______________________________________________________________________________________________________________________
// Copy Right (c) 2010, 2011 SapiensIT Consulting GmbH, all rights reserved
//_______________________________________________________________________________________________________________________
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//_______________________________________________________________________________________________________________________
// PROJECT:     sapiens.at.Core
//_______________________________________________________________________________________________________________________
// VERSION:     2.0
//_______________________________________________________________________________________________________________________
// DESCRIPTION: 
//_______________________________________________________________________________________________________________________
// LICENSE:     Different licens Types apply to different file types:
//               - Source code files are governed by the MICROSOFT PUBLIC LICENSE (Ms-PL)
//               - Binary files are governed by MSDN CODE GALLERY BINARY LICENSE
//               - Documentation files are governed by CREATIVE COMMONS ATTRIBUTION 3.0 LICENSE
//
//               The licenses can be found at the projects source location.
//               If you do not agree, don't use it!
// 
//_______________________________________________________________________________________________________________________
// Start SharePoint Branding, visit http://www.cliggin.com! Visit us on http://www.sapiens.at! Tell your friends! 
//_______________________________________________________________________________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using Sapiens.at.Core.Properties;

namespace Sapiens.at.Core.Utils
{
    /// <summary>
    /// Provides methods that help validating method arguments.
    /// </summary>
    public static class ValidationEx
    {
        /// <summary>
        /// Ensures, that the argumentValue is not equal to its types default value.
        /// </summary>
        /// <typeparam name="T">The type of the value to validate</typeparam>
        /// <param name="argumentValue">The value to validate</param>
        /// <param name="argumentName">The argument name</param>
        /// <exception cref="ArgumentException">Throws an ArgumentException if the validation fails.</exception>
        public static void ArgumentNotDefault<T>(T argumentValue, string argumentName)
        {
            if (argumentValue == null || argumentValue.Equals(default(T))) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ArgumentMustNotBeDefault, argumentName), argumentName);
        }

        /// <summary>
        /// Ensures, that the argumentValue is greater then zero.
        /// </summary>
        /// <param name="argumentValue">The value to validate</param>
        /// <param name="argumentName">The argument name</param>
        /// <exception cref="ArgumentException">Throws an ArgumentException if the validation fails.</exception>
        public static void ArgumentGtZero(int argumentValue, string argumentName)
        {
            if (argumentValue <= 0) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ArgumentMustBeGreaterThanZero, argumentName, argumentValue), argumentName);
        }

        /// <summary>
        /// Ensures, that the argumentValue is greater then zero.
        /// </summary>
        /// <param name="argumentValue">The value to validate</param>
        /// <param name="argumentName">The argument name</param>
        /// <exception cref="ArgumentException">Throws an ArgumentException if the validation fails.</exception>
        public static void ArgumentGtZero(double argumentValue, string argumentName)
        {
            if (argumentValue <= 0) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ArgumentMustBeGreaterThanZero, argumentName, argumentValue), argumentName);
        }

        /// <summary>
        /// Ensures, that the argumentValue is greater then zero.
        /// </summary>
        /// <param name="argumentValue">The value to validate</param>
        /// <param name="argumentName">The argument name</param>
        /// <exception cref="ArgumentException">Throws an ArgumentException if the validation fails.</exception>
        public static void ArgumentGtZero(float argumentValue, string argumentName)
        {
            if (argumentValue <= 0) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ArgumentMustBeGreaterThanZero, argumentName, argumentValue), argumentName);
        }

        /// <summary>
        /// Ensures, that the argumentValue is greater then zero.
        /// </summary>
        /// <param name="argumentValue">The value to validate</param>
        /// <param name="argumentName">The argument name</param>
        /// <exception cref="ArgumentException">Throws an ArgumentException if the validation fails.</exception>
        public static void ArgumentGtZero(decimal argumentValue, string argumentName)
        {
            if (argumentValue <= 0) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ArgumentMustBeGreaterThanZero, argumentName, argumentValue), argumentName);
        }
    }
}
